package com.vader.boot.aspect;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Vader
 * @date 2022/5/25
 **/
@Slf4j
public class CglibProxyTest {

    public void save(){
        log.info("save()");
    }

    public void save(int i){
        log.info("save(int)");
    }

    public void save(long l){
        log.info("save(long)");
    }


    public static void main(String[] args) {
        $CglibProxyTest cglibProxy= new $CglibProxyTest();
        CglibProxyTest test = new CglibProxyTest();
        cglibProxy.setMethodInterceptor(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                log.info("cglibProxy_test");
                return method.invoke(test,objects);
            }
        });
        cglibProxy.save();
        cglibProxy.save(1);
        cglibProxy.save(1L);

    }

}
